# Contributor: Isaac Dunham <ibid.ag@gmail.com>
# Maintainer: Aiden Grossman <agrossman154@yahoo.com>
pkgname=py3-matplotlib
_pyname=matplotlib
pkgver=3.5.2
pkgrel=0
pkgdesc="Python3 library for plots"
url="https://matplotlib.org"
# riscv64: ftbfs
arch="all !riscv64"
license="Python-2.0"
depends="
	py3-cairo
	py3-certifi
	py3-cycler
	py3-dateutil
	py3-fonttools
	py3-kiwisolver
	py3-numpy
	py3-packaging
	py3-parsing
	py3-pillow
	py3-tz
	python3-tkinter
	"
makedepends="
	python3-dev
	gfortran
	py3-numpy-dev
	freetype-dev
	libpng-dev
	tk-dev
	py3-setuptools
	qhull-dev
	py3-wheel
	py3-setuptools-scm-git-archive
	"
checkdepends="
	py3-pytest
	py3-pytest-xdist
	ttf-opensans
	"
source="https://github.com/matplotlib/$_pyname/archive/v$pkgver/matplotlib-v$pkgver.tar.gz
	$pkgname-images-$pkgver.tar.gz::https://github.com/boomanaiden154/matplotlib-test-images/releases/download/matplotlib-$pkgver/matplotlib-images.tar.gz
	freetype.patch
	test.patch
	"
builddir="$srcdir/$_pyname-$pkgver"

replaces="py-matplotlib" # Backwards compatibility
provides="py-matplotlib=$pkgver-r$pkgrel" # Backwards compatibility

prepare() {
	default_prepare

	# Use system freetype and qhull
	sed -e 's|#system_freetype = False|system_freetype = True|' -e 's|#system_qhull = False|system_qhull = True|' mplsetup.cfg.template > mplsetup.cfg
	# Install tests
	sed -i 's|#tests = False|tests = True|' mplsetup.cfg
	# Copy images from freetype mpl images repo
	cp -r ../matplotlib-images/matplotlib-$CARCH/* lib/matplotlib/tests/baseline_images/
	cp -r ../matplotlib-images/mpl_toolkits-$CARCH/* lib/matplotlib/tests/baseline_images/
}

build() {
	python3 setup.py build
}

check() {
	python3 -m venv --system-site-packages test-env
	test-env/bin/python3 setup.py install --skip-build
	test-env/bin/python3 -m pytest -n $JOBS -v --pyargs matplotlib -m "not (nonfunctional or $CARCH)"
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir" --skip-build

	# Remove tests from installation
	rm -r "$pkgdir/usr/lib/python3.10/site-packages/matplotlib/tests/"
	rm -r "$pkgdir/usr/lib/python3.10/site-packages/mpl_toolkits/tests/"
}
sha512sums="
9b6e87aeee69e106c90d1f915d2f97bf42a538bc00d885c884d2723355c2339c2cf036d2d80097db50ffa6c48a3118d96ad4cec7ff38368b19ce33eaae75f396  matplotlib-v3.5.2.tar.gz
8807fb1243b89059f75b7fd119890693c8e148d21bc1011d649a17b737facbba8a0fd5fb80e7628e1c0269e55a7c0c76f5ead948e7a2598f37347ee47f32ab23  py3-matplotlib-images-3.5.2.tar.gz
7f1360a96c9cad4946ff55ef68c8b5875c446015e1084cc65e164a62e354b0819cac51e169b7b3cd5e96e2aa68f8f27b116bd67e6daa70a9f2e53981d3081e0e  freetype.patch
fdadf88a5fd04924e1b07e291e0d4805d1aaabf09a92fa7d3e5d63f612f3492035a46432b123e2e4fc4552effb17618949731da552067a4c512afdbccd2928e6  test.patch
"
